package cn.tedu.test.luban.rpc.client;

import cn.tedu.test.luban.rpc.api.HelloService;

import java.io.*;
import java.net.Socket;

public class HelloServiceProxy implements HelloService {

    @Override
    public String sayHi(String name) throws IOException {
        //建立通信
        Socket socket = new Socket("localhost",20000);

        OutputStream outputStream = socket.getOutputStream();
        // 快速写入基本数据类型和字符串的类
        DataOutputStream dos = new DataOutputStream(outputStream);
        dos.writeUTF(name);

        // System.out.println("客户端传输序列化数据:"+name);

        InputStream inputStream = socket.getInputStream();
        DataInputStream dis = new DataInputStream(inputStream);
        String result = dis.readUTF();
        // System.out.println("客户端远程调用结果:"+result);

        return result;
    }
}
